﻿<UserControl x:Class="OpenPOS.Modules.Stock.Views.StockMaintanceView_Main"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:controls="clr-namespace:OpenPOS.Controls;assembly=OpenPOS.Controls"
    xmlns:infrastructure="clr-namespace:OpenPOS.Infrastructure.MVVM;assembly=OpenPOS.Infrastructure"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <infrastructure:CommandReference Command="{Binding AddProductCommand}" x:Key="addProductCommandRefrence" />
    </UserControl.Resources>
    <Grid Background="{DynamicResource ShadeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="300"/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <ListBox Margin="5,2.5,2.5,5" Grid.Column="0" ItemsSource="{Binding Categories}" SelectedValue="{Binding SelectedCategory, Mode=TwoWay}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

            <ListBox Margin="2.5,2.5,5,5" Grid.Column="1" ItemsSource="{Binding Products}" SelectedValue="{Binding SelectedProduct, Mode=TwoWay}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Button Content="+" Command="{StaticResource addProductCommandRefrence}" CommandParameter="{Binding}" Width="30" Height="25" />
                            <TextBlock Text="{Binding Name}" VerticalAlignment="Center" Margin="5,0,0,0" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>

        <Grid Grid.Row="0" Margin="5,5,5,5">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="75" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="250" />
            </Grid.ColumnDefinitions>

            <TextBlock Text="Date:" Grid.Column="0" Grid.Row="0" />
            <TextBlock Text="Reason:" Grid.Column="0" Grid.Row="1" />

            <DatePicker Grid.Column="1" Grid.Row="0" SelectedDate="{Binding Timestamp}" />
            <ComboBox Grid.Column="1" Grid.Row="1" Margin="0,2.5,0,0" SelectedValue="{Binding Reason}" x:Name="reasonComboBox"/>

            <ListView Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" Margin="0,10,0,0" ItemsSource="{Binding Actions}" SelectedValue="{Binding SelectedAction, Mode=TwoWay}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Item" Width="250" DisplayMemberBinding="{Binding Product.Name}" />
                        <GridViewColumn Header="Price" Width="100" DisplayMemberBinding="{Binding Product.BuyPrice, StringFormat='R0.00'}" />
                        <GridViewColumn Header="Units" Width="75" DisplayMemberBinding="{Binding Units}"/>
                    </GridView>
                </ListView.View>
            </ListView>

            <controls:Keypad Grid.Column="2" Grid.Row="0" Grid.RowSpan="3" Margin="10,0,0,0" 
                             ProcessCommand="{Binding ProcessActionsCommand}" 
                             DecrementCommand="{Binding DecreaseUnitsCommand}"
                             IncrementCommand="{Binding IncreaseUnitsCommand}"/>
        </Grid>
    </Grid>
</UserControl>
